package com.atguigu.practice;

import java.util.Scanner;

public class TheRootOfTheNum {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNextInt()){
            int n=scanner.nextInt();
            System.out.println(findTheRoot(n));
        }
    }
    public static int findTheRoot(int n){
        if(n>0&&n<10){
            return n;
        }else{
            int sum=0;
            while(n!=0){
                sum+=n%10;
                n/=10;
            }
            return findTheRoot(sum);
        }
    }
}
